package Day08;


class Personn{
    private String name;
    private String inStr;
    public Personn(){

    }
    public Personn(String name,String inStr){
        this.name = name;
        this.inStr = inStr;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInStr() {
        return inStr;
    }

    public void setInStr(String inStr) {
        this.inStr = inStr;
    }
    public boolean equals(Object obj){
        //如果两个对象为同一个对象
        if(this == obj){
            return true;
        }
        //只有Obj是Perosnn对象
        if(obj != null && obj.getClass() == Personn.class){
            Personn objectobj = (Personn)obj;
            //并且当前对象的idStr和obj对象的idStr相等时，才可以判断两个对象相等
            if(this.getInStr().equals(objectobj.getInStr())){
                return true;
            }

        }
        return false;
    }
}
class Dog{}
public class Equals {
    public static void main(String[] args) {
/*
        Personn p = new Personn();
        System.out.println("Personn 对象是否equals Dog 对象？" + p.equals(new Dog()));
        System.out.println("Personn 对象是否equals String 对象？" + p.equals(new String("Hello")));

*/
        Personn p1 = new Personn("孙悟空","1234343433");
        Personn p2 = new Personn("孙行者","1234343433");
        Personn p3 = new Personn("孙悟饭","99933433");
        System.out.println("p1和p2是否相等? " + p1.equals(p2));
        System.out.println("p2和p3是否相等? " + p1.equals(p3));





    }

}
